package com.leo.model;

/**
 * @ClassName LinkedStack
 * @Description 链表实现栈
 * @Author wangss
 * @date 2022.01.29 14:46
 * @Version 1.0
 */
public class LinkedStack {

    private Node node;

    /**
     * 进栈
     *
     * @param data
     * @return
     */
    public boolean push(int data) {
        if (null == node) {
            node = new Node(data);
            return true;
        }
        Node tmp = new Node(data);
        tmp.next = node;
        node = tmp;
        return true;
    }

    /**
     * 出栈
     *
     * @return
     */
    public int pop() {
        if (null == node) {
            return -1;
        }
        int data = node.data;
        node = node.next;
        return data;
    }
}
